﻿using DevComponents.DotNetBar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Kimd.Communication
{
    public partial class FrmSendCmd : Office2007Form
    {
        private Dictionary<string, string> CmdDic = new Dictionary<string, string>();
        public FrmSendCmd()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterParent;
            this.EnableGlass = false;
        }
        public FrmSendCmd(Dictionary<string, string> cmdDic):this()
        {
            CmdDic = cmdDic;
        }
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (tb_Cmd.Text != "" &&tb_CmdName.Text != "")
            {
                if (CmdDic.Keys.Contains(tb_CmdName.Text))
                {
                    MessageBox.Show("指令名称已经存在!");
                    return;
                }
                string value = tb_Cmd.Text;
                CmdDic.Add(tb_CmdName.Text,value);
                this.Tag = CmdDic;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
        
        private void FrmSendCmd_Load(object sender, EventArgs e)
        {
            string[] cmd = this.CmdDic.Keys.ToArray();
            this.Cob_Cmd.Items.Clear();
            this.Cob_Cmd.Items.AddRange(cmd);
            this.Cob_Cmd.SelectedIndex = -1;
        }

        private void Cob_Cmd_SelectedIndexChanged(object sender, EventArgs e)
        {
            string name = (string)Cob_Cmd.SelectedItem;
            string cmd = CmdDic[name];
            this.tb_Cmd.Text = cmd;
        }
    }
}
